package coc.example.script.crawler.坪山通;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import coc.core.CrawlerConfig;
import coc.core.Data;
import coc.core.SpiderResult;
import coc.example.script.crawler.BaseCrawler;

public class PstCrawler extends BaseCrawler {
	private PstService pstService;
	private Map<String, String> navMap = new HashMap<String, String>();

	public PstCrawler(CrawlerConfig config) {
		super(config);
		navMap.put("幼儿园一览表", "id0001");
	}

	@Override
	protected Integer saveSpiderResult(SpiderResult spiderResult) {
		Data data = (Data) spiderResult.getData();
		// String navId = navMap.get(data.get("nav"));
		// if (navId != null) {
		log.debug("-------------------------------------------------------------------------------------------------");
		log.debug(data.toString());
		log.debug("-------------------------------------------------------------------------------------------------");
		PstEntity entity = new PstEntity();
		// entity.setNavId(navId);
		entity.setTitle(data.get("title").toString());
		entity.setText(data.get("text").toString());
		entity.setPublishDate((Date) data.get("publishDate"));
		// entity.setCoordinates(data.get("coordinates").toString());
		pstService.savePstEntity(entity);
		return spiderResult.getDataSize();
		// }
		// return 0;
	}

	public void setPstService(PstService pstService) {
		this.pstService = pstService;
	}
}
